package de.karlNet.sambamanager.ldapController.commands;

import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;

import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.stereotype.Controller;

import de.karlNet.sambamanager.ldapModel.LdapContainer;

@Controller
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class CreateOrganizationalUnit extends BaseCommand {

	public void createOrganisationalUnit(LdapContainer container) {
		DistinguishedName distinguisedName = new DistinguishedName(
				container.getDn());

		Attributes attrs = new BasicAttributes(true); // case-ignore
		Attribute objclass = new BasicAttribute("objectclass");
		objclass.add("top");
		objclass.add("organizationalUnit");
		attrs.put(objclass);

		ldapTemplate.bind(distinguisedName, null, attrs);
		this.resetTrees();
	}
}
